var replyCount;//跟贴数
$(document).ready(function(){
			 /**查看跟贴**/
			getReplyCount();
			$("#btnUpdate").click(function()
			{
				if((checkTitle())&&(checkNewsContent())){
					$("#newsUpdateForm").submit();
				}
				
			});
			if(replyCount>0){//查询跟贴列表
				loadNewsReply();
			}
			
});
function checkTitle(){

	var title=$("#title").val();
	if(title.length==0){
		alert("标题不能为空");
		$("#title").focus();
		return false;
	}
	if(title.length<5){
		alert("标题长度太短，不能少于5个字符");
		$("#title").focus();
		return false;
	}
	return true;
}
function checkNewsContent(){
            var sd = CKEDITOR.instances.newsContent.getData();
            if (sd.length == 0) {
                alert("新闻内容不能为空");
				$("#newsContent").focus();
                return false;
            }
            if (sd.length < 5) {
               alert("新闻内容长度太短，不能少于5个字符");
				$("#newsContent").focus();
                return false;
            };
			return true;
}
function getReplyCount(){
	var params = {
		    "newsId":$("#nd").val()
		    };
		    $.ajax({
		        type: "post",
		        url: "admin/reply!replyCount",
		        data: params,
		        dataType: "json",
		        success: function(data){
					replyCount=data;
		            $("#showReplyCount").append(replyCount);// 显示跟贴数
		            return true;
		        },
		        error: function(data){
		            alert("error");
		            return false;
		        }
		    });
}

function loadNewsReply(){
	var params = {
		    "newsId":$("#nd").val()
		    };
			alert("goog");
			$.ajax({
		        type: "post",
		        url: "admin/reply!newsFirstReply",
		        data: params,
		        dataType: "json",
		        success: function(data){
					$.each(data.replyList,function(index,element){
						$("#replyList").append(index+1+"楼&nbsp;&nbsp;用户："+element.tbUser.userName+"&nbsp;&nbsp;"+element.replyTime.substr(0,10)+" "+element.replyTime.substr(11,18)+"<br>"+element.content+"<br>");
						//<a href='admin/reply!deleteReplyById?newsId="+element.replyId+"'>删除</a>
					});
		            return true;
		        },
		        error: function(data){
		            alert("error");
		            return;
		        }
		    });
}
